﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Abp.AspNetCore.Mvc.Extensions;
using FwProject.Controllers;
using FwProject.Settlement;
using FwProject.Settlement.Dto;
using Microsoft.AspNetCore.Mvc;

namespace FwProject.Web.Mvc.Controllers
{
    public class FinanceController : FwProjectControllerBase
    {
        private readonly ISettlementAccountAppService _settlementAccountAppService;

        public FinanceController(ISettlementAccountAppService settlementAccountAppService)
        {
            _settlementAccountAppService = settlementAccountAppService;
        }

        #region 结算账户

        public async Task<IActionResult> SettlementAccount(int? pageIdx, string keyword = "")
        {
            var pa = pageIdx ?? 1;

            var s = await _settlementAccountAppService.GetPagedListAsync(pa, 20, keyword);
            if (Request.IsAjaxRequest())
                return PartialView("SettlementAccountPartial", s);

            return View(s);
        }

        public IActionResult CreateAccount()
        {
            return View(new SettlementAccountEnterDto());
        }

        [HttpPost]
        public async Task<IActionResult> CreateAccount(SettlementAccountEnterDto input)
        {
            var id = await _settlementAccountAppService.CreateAsync(input);
            return Json(id);
        }

        public async Task<IActionResult> EditAccount(Guid id)
        {
            var entity = await _settlementAccountAppService.GetEnterDto(id);
            return View(entity);
        }

        [HttpPost]
        public async Task<IActionResult> EditAccount(Guid id, SettlementAccountEnterDto input)
        {
            await _settlementAccountAppService.ModifyAsync(id, input);
            return Json(id);
        }

        public async Task<IActionResult> DeleteAccount(Guid id)
        {
            await _settlementAccountAppService.DeleteAsync(id);
            return Json(id);
        }
        #endregion
    }
}